package com.atguigu.gmall.cart.service.impl;

import com.atguigu.gmall.cart.mapper.CartInfoMapper;
import com.atguigu.gmall.cart.service.CartInfoAsyncService;
import com.atguigu.gmall.model.cart.CartInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author: 李旭
 * @create: 2021-09-07 15:12
 **/
@Service
public class CartInfoAsyncServiceImpl implements CartInfoAsyncService {

    @Autowired
    private CartInfoMapper cartInfoMapper;
    //更新购物车 异步方式 子线程
    @Override
    @Async
    public void updateAsync(CartInfo cartInfo) {
        System.out.println("updateAsync子线程:" + Thread.currentThread().getName());
        cartInfoMapper.update(cartInfo,new QueryWrapper<CartInfo>()
         .eq("user_id",cartInfo.getUserId())
         .eq("sku_id",cartInfo.getSkuId()));
    }
    //添加购物车 异步方式 子线程
    @Override
    @Async
    public void insertAsync(CartInfo cartInfo) {
        try {
            System.out.println("insertAsync子线程:" + Thread.currentThread().getName());
            cartInfoMapper.insert(cartInfo);
        } catch (Exception e) {
            //e.printStackTrace();
            //打印日志
        }
    }
}
